package com.chen.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//
@WebServlet(value = "/s3", loadOnStartup = 6)
public class Servlet03 extends HttpServlet {
    public Servlet03() {
        System.out.println("构造方法执行了");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("初始方法执行了");
    }

/*
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("service方法执行了");
    }
*/

    // 本类继承了HttpServlet抽象类在HttpServlet类中对service进行处理
    // HttpServlet 处理的逻辑就是通过获取请求行中请求来调用对应的do**方法
    // 而在HttpServlet中的do**方法的作用就是故意返回错误的状态码  405（不支持请求方式）
    // 所以在这里可以通过重写do**方法来处理接收请求的业务代码

    // 总结：在实现HttpServlet抽象类中重写service或者do**方法都可以都可以完成处理的请求的业务代码
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行了doGet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行了doPost");
    }

    @Override
    public void destroy() {
        System.out.println("销毁方法执行了");
    }
}
